<?php
/*** 
 *
 *
 *
 **/
require_once '../db/db.php';
require_once modpath('util','perm');
function getForum( $fid ) { 

  // later these should be warped back to a switch around/public/private/view/etc
  if( !hasPerm('forum.view.public') ) 
    return MSG_UNAUTHORIZED;

  $GLOBALS['__QNUM']++;
  try {
    $db = openDbConn();

    // validate fid
    $fid = intval((int)$fid);

    $tmp = $db->query("SELECT id, title, datum, rank FROM forum
                          WHERE forum.id = ${fid} ORDER BY rank;");
    $data = $tmp->fetchAll( PDO::FETCH_ASSOC );
    $tmp = null;
    return $data;
    
  } catch ( PDOException $e ) {
    print "ERROR: " . $e->getMessage() . "<br />";
    die();
  }
};
function getFora( ) { 
  if( !hasPerm('forum.view.public') ) 
    return MSG_UNAUTHORIZED;

  $GLOBALS['__QNUM']++;
  try {
    $db = openDbConn();
    $tmp = $db->query("SELECT id, title, datum, rank FROM forum;");
    $data = $tmp->fetchAll( PDO::FETCH_ASSOC );
    $tmp = null;
    return $data;
    
  } catch ( PDOException $e ) {
    print "ERROR: " . $e->getMessage() . "<br />";
    die();
  }
};
function getForaRange( $start, $inc = DEF_FORUM_INC) { 
  if( !hasPerm('forum.view.public') ) 
    return MSG_UNAUTHORIZED;

  $GLOBALS['__QNUM']++;
  try {
    $db = openDbConn();
    $tmp = $db->query("SELECT id, title, datum, rank FROM forum
                          ORDER BY rank LIMIT $start, $inc;");
    $data = $tmp->fetchAll( PDO::FETCH_ASSOC );
    $tmp = null;
    return $data;
    
  } catch ( PDOException $e ) {
    print "ERROR: " . $e->getMessage() . "<br />";
    die();
  }
};

?>
